package com.hzx.demo.activity;

import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

import com.hzx.demo.R;
import com.hzx.demo.helper.PhotoModule;
import com.hzx.demo.util.Entry;
import com.hzx.demo.util.HZXLog;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

/**
 * Created by ldkxingzhe on 2016/6/28.
 */
@Entry(desc = "拍照DIY", createTime = "2016-06-28")
@EActivity(R.layout.activity_take_photo)
public class TakePhotoActivity extends AppCompatActivity implements SurfaceHolder.Callback {
    @SuppressWarnings("unused")
    private static final String TAG = "TakePhotoActivity";

    @ViewById(R.id.sv_camera_preview)
    protected SurfaceView mCameraPreView;

    private PhotoModule photoModule = new PhotoModule();

    @AfterViews
    protected void afterView(){
        HZXLog.v(TAG, "afterView");
        mCameraPreView.getHolder().addCallback(this);
    }

    @Click(R.id.iv_take_picture)
    protected void takePicture(){
        HZXLog.v(TAG, "takePicture");
        photoModule.takePicture(Environment.getExternalStorageDirectory() + "/hzxdemo/test.jpeg");
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        photoModule.openCamera(false, mCameraPreView);
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {

    }
}
